/**
 * 时事通讯客户端sockit.io
 */
import io from 'socket.io-client'
/**
 * 初始化客户端的sockitIo
 */
function initIo() {
   if (!io.socket) {
      //连接socket
      io.socket = io('ws://localhost:5000')
      //获取服务端返回的消息
      io.socket.on('receiveMsg', function (chatMsg) {
         console.log('客户端接收服务端返回的消息', chatMsg)
      })
   }
}

/**
 * 客户端向服务端发送消息
 * @param {String} from 发送源Id
 * @param {String} to 接收源Id
 * @param {String} content 发送的内容
 */
export const sendMessageIo = ({ from, to, content }) => {
   return () => {
      initIo();
      //把消息发送给socket服务端
      io.socket.emit('sendMsg', { from, to, content })
      console.log(1111)
   }
}